package cn.itcast.nems.oldems.service.sync;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * author liyong
 * create: 2024-03-19 11:36:11
 **/
@RefreshScope
@Component
public class OldEmsSyncConfig {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private volatile boolean sync;

    private Set<Integer> ignoredSjcIds;

    @Value("${ems.sync.sjc}")
    public void setSync(boolean sync) {
        logger.info("Old ems sync from '{}' to '{}'", this.sync, sync);
        this.sync = sync;
    }

    public boolean isSysnc() {
        return this.sync;
    }


    public Set<Integer> getIgnoredSjcIds() {
        return ignoredSjcIds;
    }

    @Value("${ems.sync.ignoredSjcIds:}")
    public void setIgnoredSjcIds(Set<Integer> ignoredSjcIds) {
        logger.info("Old ems ignoredSjcIds set to '{}'", ignoredSjcIds);
        this.ignoredSjcIds = ignoredSjcIds;
    }

    public boolean isIgnoredSjcId(Integer sjcId) {
        boolean ignored = false;
        if (this.ignoredSjcIds != null && this.ignoredSjcIds.contains(sjcId)) {
            ignored = true;
        }
        return ignored;
    }
}
